package com.itheima.service.Impl;

import com.github.pagehelper.PageHelper;
import com.itheima.domain.City;
import com.itheima.domain.Province;
import com.itheima.domain.Student;
import com.itheima.domain.User;
import com.itheima.mapper.JLMapper;
import com.itheima.service.JLService;
import com.itheima.utils.MapperUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @param
 * @return
 */
public class JLServiceImpl implements JLService {
    @Override
    public List<Province> findAllProvince() {
        /*工具类获取session对象*/
        SqlSession session = MapperUtil.getSession();
        //session获取接口代理对象
        JLMapper mapper = session.getMapper(JLMapper.class);
        //调用方法
        List<Province> list = mapper.findAllProvince();
       MapperUtil.close(session);
        return list;
    }

    @Override
    public List<City> findCityById(int id) {
        //定义返回值
        List<City> list=null;
        //工具类干活
        SqlSession session = MapperUtil.getSession();
        JLMapper mapper = session.getMapper(JLMapper.class);
        list=mapper.findCityById( id);
        MapperUtil.close(session);
        return list;
    }

    @Override
    public User login(String username, String password) {
        //定义返回值
        User user=null;
        //工具类走起
        SqlSession session = MapperUtil.getSession();
        JLMapper mapper = session.getMapper(JLMapper.class);
        user=mapper.login(username,password);
        return user;
    }

    @Override
    public List<Student> findAll(int pageNum ) {
        //定义返回值
        List<Student> list=null;
        //工具类走起
        SqlSession session = MapperUtil.getSession();
        JLMapper mapper = session.getMapper(JLMapper.class);
        PageHelper.startPage(pageNum,3);
        list = mapper.findAll();
        return list;
    }
}
